package org.chengn.level_easy.context1154;

/**
 * @Title: Context1154
 * @Author ChengN
 * @Package org.chengn.level_easy.context1154
 * @Date 2023/12/31 0:14
 * @description: 一年中的第几天
 */
public class Context1154 {
    int[] dates = new int[]{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    public int dayOfYear(String date) {
        String[] dateList = date.split("-");
        if (isRun(dateList[0])) {
            dates[2] = 29;
        }

        int res = 0;
        for (int i = 0; i < Integer.parseInt(dateList[1]); ++i) {
            res += dates[i];
        }
        return res + Integer.parseInt(dateList[2]);
    }

    boolean isRun(String year) {
        int i = Integer.parseInt(year);
        return i % 100 == 0 && i % 400 == 0 || i % 100 != 0 && i % 4 == 0;
    }
}
